package smcms.service.order.service.impl;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import smcms.service.order.entity.*;
import smcms.service.order.mapper.BusinessDisplayMapper;
import smcms.service.order.service.BusinessDisplayService;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class BusinessDisplayServiceImpl implements BusinessDisplayService {
    @Autowired
    private BusinessDisplayMapper businessDisplayMapper;
    @Override
    public List<WeekSaleResp> getWeekSales(WeekSaleReq req) {
        if (ObjectUtils.isEmpty(req.getCloudId())) {
            throw new IllegalArgumentException("云id不能为空！");
        }
        List<WeekSaleResp> weekSale = businessDisplayMapper.getWeekSale(req);
        return weekSale;
    }

    @Override
    public List<WeekSaleResp> getWeekInAndOut(WeekSaleReq req) {
        if (ObjectUtils.isEmpty(req.getCloudId())) {
            throw new IllegalArgumentException("云id不能为空！");
        }
        List<WeekSaleResp> weekInAndOut = businessDisplayMapper.getWeekInAndOut(req);
        return weekInAndOut;
    }

    @Override
    public List<RangeResp> getProductRange(WeekSaleReq req) {
        List<RangeResp> productRange = businessDisplayMapper.getProductRange(req);
        List<RangeResp> rangeRespList = productRange
                .stream()
                .sorted(
                        Comparator
                                .comparing(RangeResp::getMoney)
                                ).collect(Collectors.toList());
        return rangeRespList;
    }

    @Override
    public List<SalePercent> getSalePercent(WeekSaleReq req) {
        List<SalePercent> salePercent = businessDisplayMapper.getSalePercent(req);
        return salePercent;
    }

    @Override
    public List<InventoryResp> getInventory(WeekSaleReq req) {
        List<InventoryResp> inventory = businessDisplayMapper.getInventory(req);
        return inventory;
    }

    @Override
    public List<RatioResp> getRatio(WeekSaleReq req) {
        List<RatioResp> ratio = businessDisplayMapper.getRatio(req);
        return ratio;
    }

    @Override
    public Statistics getStatistics(WeekSaleReq req) {
        Statistics statistics = businessDisplayMapper.getStatistics(req);
        return statistics;
    }
}
